package com.example.sourcecodelearning.controller;

import cn.hutool.json.JSONObject;
import com.example.framework.common.pojo.R;
import com.example.framework.web.annotation.LogRequest;
import com.example.sourcecodelearning.modules.test.TestService;
import com.example.sourcecodelearning.modules.zendesk.ZendeskService;
import com.example.sourcecodelearning.modules.zendesk.dto.WebSupportRmaRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuzhenxin
 * @date 2023/3/27
 */
@PermitAll
@Tag(name = "测试", description = "这里面的接口无需登录使用")
@RestController
@RequestMapping("/test")
@LogRequest
public class TestController {

    @Resource
    private TestService testService;

    @Resource
    private ZendeskService zendeskService;

    @Operation(summary = "测试aop")
    @GetMapping("/aop")
    public R<String> testAOP() {
        testService.testAOP();
        return R.success();
    }

    @Operation(summary = "Zendesk 创建 ticket")
    @PostMapping(value = "/createTicket", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<JSONObject> createTicket(@Valid @ModelAttribute WebSupportRmaRequest webSupportRmaRequest) {
        JSONObject ticket = zendeskService.createTicket(webSupportRmaRequest);
        return R.success(ticket);
    }

}
